package com.nuc.thread.status;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @Description join的测试
 * @Author 诗酒趁年华
 * @Version V1.0.0
 * @Date 2021/5/5
 */
@Slf4j(topic = "JoinTest1")
public class JoinTest1 {
    static int r = 1;
    public static void main(String[] args) throws InterruptedException {
        test();
    }

    private static void test() throws InterruptedException {
        log.debug("开始");
        Thread thread = new Thread("t1"){
            @Override
            public void run() {
                log.debug("开始");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                r = 10;
                log.debug("结束");
            }
        };
        thread.start();
        thread.join();//等待子线程执行结束
        log.debug("r的最终结果为{}",r);
        log.debug("结束");

    }
}
